package com.example.demo.mapper;

import org.apache.ibatis.annotations.*;
import com.example.demo.domain.Comment;
import java.util.List;

@Mapper
public interface CommentMapper {

    // Find comments for a given blog post
    @Results({
            @Result(property = "id", column = "id"),
            @Result(property = "postId", column = "post_id"),
            @Result(property = "authorName", column = "author_name"),
            // @Result(property = "email", column = "email"), // Uncomment if email field is added in table
            @Result(property = "content", column = "content"),
            @Result(property = "creationDate", column = "creation_date")
    })
    @Select("SELECT * FROM comment WHERE post_id = #{postId}")
    List<Comment> findByPostId(Long postId);

    // Insert a new comment
    @Insert("INSERT INTO comment (post_id, author_name, content, creation_date) VALUES (#{postId}, #{authorName}, #{content}, NOW())")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Comment comment);

    // Delete a specific comment
    @Delete("DELETE FROM comment WHERE id = #{id}")
    int deleteById(Long id);

    // Additional CRUD operations can be defined here if needed
    // ...
}
